<template>
    <div class="app-container">
        <el-form :model="searchdata" size="small" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="姓名" prop="nickName">
                <el-input v-model="searchdata.nickName" placeholder="请输入姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="手机号" prop="phonenumber">
                <el-input v-model="searchdata.phonenumber" placeholder="请输入手机号" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="入职时间">
                <el-date-picker v-model="searchdata.startTime" type="date" placeholder="开始时间"  value-format="yyyy-MM-dd" style="width: 150px">
                </el-date-picker>
                <el-date-picker v-model="searchdata.endTime" type="date" placeholder="结束时间" value-format="yyyy-MM-dd" style="width: 150px">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索
                </el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-table v-loading="loading" :data="zhanghuList">
            <el-table-column label="姓名" align="center" prop="nickName" />
            <el-table-column label="手机号" align="center" prop="phonenumber" />
            <el-table-column label="入职时间" align="center" prop="createTime">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime, '{YY}-{MM}-{DD}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="账户余额" align="center" prop="puHaveMoney" />
            <el-table-column label="冻结金额" align="center" prop="puFieezeMoney" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-s-finance" @click="yinghangka(scope.row)">银行卡
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-document" @click="details(scope.row)">交易明细
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="frozenjine(scope.row)">冻结金额
                    </el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="frozen(scope.row)">查看冻结金额</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="searchdata.pageNum"
            :limit.sync="searchdata.pageSize" @pagination="getList" />
        <!-- 冻结金额操作 -->
        <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
            <el-form :model="form" ref="form" :rules="rules" size="small" :inline="true" label-width="150px">
                <el-form-item label="冻结金额" prop="cmmoney">
                    <el-input v-model="form.cmmoney" placeholder="请输入冻结金额" type="text" clearable style="width: 180px">
                    </el-input>
                </el-form-item>
                <el-form-item label="备注" prop="remark">
                    <el-input v-model="form.remark" placeholder="备注" type="textarea" clearable style="width: 180px">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="sbumit">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import { selectAllZkwlYuangong, djinsertjiedong } from "@/api/puser/account.js"
import { format } from "path";
export default {
    data() {
        return {
            showSearch: true,
            searchdata: {
                nickName: '',
                phonenumber: '',
                startTime: '',
                endTime: '',
                pageNum: 1,
                pageSize: 10,
            },
            zhanghuList: [],
            loading: true,
            total: 0,
            open: false,
            title: '',
            form: {
                userId: '',
                cmmoney: '',
                remark: '',
            },
            rules: {
                cmmoney: [{ required: true, message: "冻结金额不能为空", trigger: "blur" }]
            }
        }
    },
    created() {
        this.getList();
    },
    methods: {
        async getList() {
            let res = await selectAllZkwlYuangong(this.searchdata);
            if (res.code == 200) {
                this.loading = false;
                this.zhanghuList = res.rows;
                this.total = res.total;
            }
        },
        //   银行卡
        yinghangka(row) {
            this.$router.push({
                name: "yinhangka",
                query: { userId: row.userId }
            })
        },
        // 交易明细
        details(row) {
            this.$router.push({
                name: "jiaoyimingxi",
                query: { userId: row.userId }
            })
        },
        // 冻结金额
        frozenjine(row) {
              this.form = {
                userId: '',
                cmmoney: '',
                remark: '',
            }
            this.form.userId = row.userId;
            this.open = true;
            this.title = "冻结金额"
        },
        // 确定按钮操作
        sbumit() {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    djinsertjiedong(this.form).then(response => {
                        if (response.data.code == 200) {
                            this.open = false;
                            this.form = {
                                userId: '',
                                cmmoney: '',
                                remark: '',
                            }
                            this.$modal.msgSuccess(response.data.msg);
                            this.getList();
                        } else {
                            this.$modal.msgError(response.data.msg);
                            this.open = false;
                            this.form = {
                                userId: '',
                                cmmoney: '',
                                remark: '',
                            }
                        }

                    })
                }
            })
        },
        cancel() {
            this.open = false;
            this.form = {
                userId: '',
                cmmoney: '',
                remark: '',
            }
        },
        // 查看冻结金额
        frozen(row) {
            this.$router.push({
                name: "forzen",
                query: { userId: row.userId }
            })
        },
        // 搜索
        handleQuery() {
            selectAllZkwlYuangong(this.searchdata).then(response => {
                if (response.code == 200) {
                    this.zhanghuList = response.rows;
                    this.total = response.total;
                }
            })
        },
        resetQuery() {
            this.searchdata = {
                nickName: '',
                phonenumber: '',
                startTime: '',
                endTime: '',
            },
                this.getList();
        }
    }
}
</script>